home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 099 (1989-05-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 099 (1989-05-15)(Ossowski, Stefan)(DE)(PD).adf / PCQ / Runtime / pcqstart.asm < prev    next >
Assembly Source File  |  1989-03-31  |  3KB  |  158 lines

  1.  
  2.     SECTION    ONE
  3.  
  4. *    PCQStart.asm (of PCQ Pascal runtime library)
  5. *    Copyright (c) 1989 Patrick Quaid
  6.  
  7. *    This is the startup and shutdown code for the programs.
  8. *    Note that a few changes have got to take place here before PCQ
  9. *    programs can be run from the WorkBench.
  10.  
  11.     XREF    _CommandLine    ; from the main program
  12.     XREF    _AbsExecBase
  13.     XREF    _LVOOpenLibrary
  14.     XREF    _LVOCloseLibrary
  15.  
  16.     XREF    _LVOInput
  17.     XREF    _LVOOutput
  18.     XREF    _LVOClose
  19.  
  20.     XREF    _LVOFreeRemember
  21.  
  22.     XREF    newkey
  23.     XREF    filekey
  24.  
  25.     XDEF    _stdin
  26.     XDEF    _stdout
  27.     XDEF    stdinbuffed
  28.     XDEF    stdinbuffer
  29.     XDEF    _p%DOSBase
  30.     XDEF    _p%IntuitionBase
  31.     XDEF    _p%MathBase
  32.  
  33. ;    Define entry point
  34.  
  35.     xdef    _p%initialize
  36. _p%initialize
  37.  
  38. ;    Save stack pointer for exit() routine
  39.  
  40.     move.l    sp,StkPtr    ; save stack pointer
  41.     add.l    #4,StkPtr    ; account for this jsr to get to original
  42.  
  43. ;    copy command line into _CommandLine
  44.  
  45.     move.l    #_CommandLine,a1
  46. 1$    move.b    (a0)+,d1
  47.     move.b    d1,(a1)+
  48.     bne    1$
  49.     
  50. ;    Open libraries
  51.  
  52.     lea    intuitionname,a1
  53.     clr    d0
  54.     move.l    _AbsExecBase,a6
  55.     jsr    _LVOOpenLibrary(a6)
  56.     move.l    d0,_p%IntuitionBase
  57.     beq    _p%wrapitup
  58.  
  59.     lea    dosname,a1
  60.     clr    d0
  61.     jsr    _LVOOpenLibrary(a6)
  62.     move.l    d0,_p%DOSBase
  63.     beq    _p%wrapitup
  64.  
  65.     lea    mathname,a1
  66.     clr    d0
  67.     jsr    _LVOOpenLibrary(a6)
  68.     move.l    d0,_p%MathBase
  69.     beq    _p%wrapitup
  70.  
  71. ;    Find standard file handles
  72. ;    This part will have to be adjusted for WorkBench.
  73.  
  74.     move.l    _p%DOSBase,a6
  75.     jsr    _LVOInput(a6)
  76.     move.l    d0,_stdin
  77.     beq    _p%wrapitup
  78.     jsr    _LVOOutput(a6)
  79.     move.l    d0,_stdout
  80.     beq    _p%wrapitup
  81.     rts
  82.  
  83. ;    The shut-down code
  84.  
  85.     xdef    _p%wrapitup
  86. _p%wrapitup:
  87.  
  88.     tst.l    filekey        ; close all open files
  89.     beq.s    2$
  90.     move.l    _p%DOSBase,a6
  91.     move.l    filekey,a0
  92. 1$    move.l    (a0),d1
  93.     move.l    a0,-(sp)
  94.     jsr    _LVOClose(a6)
  95.     move.l    (sp)+,a0
  96.     move.l    14(a0),a0
  97.     move.l    a0,d0
  98.     bne.s    1$
  99.  
  100. 2$    tst.l    newkey        ; return all allocated memory
  101.     beq.s    3$
  102.     lea    newkey,a0
  103.     moveq.l    #-1,d0
  104.     move.l    _p%IntuitionBase,a6
  105.     jsr    _LVOFreeRemember(a6)
  106. 3$
  107.     move.l    _AbsExecBase,a6
  108.     move.l    _p%IntuitionBase,a1
  109.     move.l    a1,d0                ; to set flags
  110.     beq.s    4$
  111.     jsr    _LVOCloseLibrary(a6)
  112. 4$
  113.     move.l    _p%DOSBase,a1
  114.     move.l    a1,d0                ; set flags
  115.     beq.s    5$
  116.     jsr    _LVOCloseLibrary(a6)
  117. 5$
  118.     move.l    _p%MathBase,a1
  119.     move.l    a1,d0
  120.     beq.s    6$
  121.     jsr    _LVOCloseLibrary(a6)
  122. 6$
  123.     moveq.l    #0,d0
  124.     rts
  125.  
  126.     XDEF    _exit
  127.     XDEF    _p%exit
  128. _exit
  129.     move.l    4(sp),d0
  130. _p%exit
  131.     move.l    d0,-(sp)
  132.     jsr    _p%wrapitup
  133.     move.l    (sp)+,d0
  134.     move.l    StkPtr,sp
  135.     rts
  136.  
  137.     SECTION    TWO,DATA
  138.  
  139. stdinbuffed    dc.b    0
  140. stdinbuffer    dc.b    0
  141. dosname        dc.b    'dos.library',0
  142. intuitionname    dc.b    'intuition.library',0
  143. mathname    dc.b    'mathffp.library',0
  144.  
  145.     CNOP    0,2
  146.  
  147. _p%DOSBase    dc.l    0
  148. _p%IntuitionBase dc.l    0
  149. _p%MathBase    dc.l    0
  150.  
  151.     SECTION    THREE,BSS
  152.  
  153. StkPtr        ds.l    1
  154. _stdin        ds.l    1
  155. _stdout        ds.l    1
  156.  
  157.     END
  158.